
component output="false" extends="AbsService" accessors="true" {

	// Delegate
	property name="PreferenceDelegate" type="it.millemultimedia.easyBlog.delegate.PreferenceDelegate";

	public it.millemultimedia.easyBlog.service.PreferenceService function init(){
		
		return this;
	}
	
	public it.millemultimedia.easyBlog.validator.PreferenceValidator function getValidator(){
		
		return getPreferenceDelegate().getValidator();
	}
	
	public it.millemultimedia.easyBlog.model.Preference[] function createPreferenceList( required String list, required String propertyName ){
		
		return getPreferenceDelegate().createList( arguments.list, arguments.propertyName );
	}
	
	public it.millemultimedia.easyBlog.model.Preference function new(){
		
		return getPreferenceDelegate().createInstance();
	}
	
	public it.millemultimedia.easyBlog.model.Preference function getPreference( required Any Preference ){
		
		return getPreferenceDelegate().read( arguments.Preference );
	}
	
	public it.millemultimedia.easyBlog.model.Preference[] function getPreferences( required Any Preference ){
		
		return getPreferenceDelegate().list( arguments.Preference );
	}
	
	public boolean function preferenceExists( required Any Preference ){
		var result = getPreferenceDelegate().list( arguments.Preference );
		
		return arrayLen( result ) gt 0;
	}
	
	public void function savePreference( required Any Preference ){
	
		transaction{
		
			try{
				
				
				if( arguments.Preference.getidPreference()  eq 0 ){
				
					this.createPreference( arguments.Preference );
				
				}else if( arguments.Preference.getIdPreference() gt 0 ){
				
					this.updatePreference( arguments.Preference );
				
				}else{
				
					throw( message="Preference id property have undefined value." );
				
				}
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
			
			}
		
		}
		
	}
	
	public void function createPreference( required Any Preference ){
	
		transaction{
		
			try{
			
				getPreferenceDelegate().create( arguments.Preference );
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
			
			}
		
		}
		
	}
	
	public void function updatePreference( required Any Preference ){
	
		transaction{
		
			try{
			
				getPreferenceDelegate().update( arguments.Preference );
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
			
			}
		
		}
		
	}
	
	public void function deletePreference( required Any Preference ){
	
		transaction{
		
			try{
			
				getPreferenceDelegate().delete( arguments.Preference );
				
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
							
			}
			
		}
		
	}
	
}
